// c:\users\de'l'l\desktop\lkchongxie\重写\pages\test\bmi\bmi
Page({
    data: {
        progress: 0,
        commentList: [{
                userPhoto: 'https://sf6-ttcdn-tos.pstatp.com/img/user-avatar/caa8f3b186a137a00aa26899533c0198~300x300.image',
                comment: '测试结果这么准的吗'
            }, {
                userPhoto: 'https://sf6-ttcdn-tos.pstatp.com/img/user-avatar/caa8f3b186a137a00aa26899533c0198~300x300.image',
                comment: '没想到啊没想到'
            }, {
                userPhoto: 'https://sf6-ttcdn-tos.pstatp.com/img/user-avatar/caa8f3b186a137a00aa26899533c0198~300x300.image',
                comment: '啦啦啦啦啦啦啦'
            }, {
                userPhoto: 'https://sf6-ttcdn-tos.pstatp.com/img/user-avatar/caa8f3b186a137a00aa26899533c0198~300x300.image',
                comment: '建议重生 呜呜呜呜'
            }, {
                userPhoto: 'https://sf6-ttcdn-tos.pstatp.com/img/user-avatar/caa8f3b186a137a00aa26899533c0198~300x300.image',
                comment: ' 原来我的数值这么高'
            }, {
                userPhoto: 'https://sf6-ttcdn-tos.pstatp.com/img/user-avatar/caa8f3b186a137a00aa26899533c0198~300x300.image',
                comment: '哈哈哈哈哈哈我的还不错'
            },
            // {
            //     userPhoto: 'https://sf6-ttcdn-tos.pstatp.com/img/user-avatar/caa8f3b186a137a00aa26899533c0198~300x300.image',
            //     comment: '77777777777'
            // }, {
            //     userPhoto: 'https://sf6-ttcdn-tos.pstatp.com/img/user-avatar/caa8f3b186a137a00aa26899533c0198~300x300.image',
            //     comment: '88888888888'
            // }, {
            //     userPhoto: 'https://sf6-ttcdn-tos.pstatp.com/img/user-avatar/caa8f3b186a137a00aa26899533c0198~300x300.image',
            //     comment: '99999999999'
            // }, {
            //     userPhoto: 'https://sf6-ttcdn-tos.pstatp.com/img/user-avatar/caa8f3b186a137a00aa26899533c0198~300x300.image',
            //     comment: '00000000000000'
            // },
        ],
    },
    onLoad: function(options) {
        console.log(options);
        if (options.type == "4") {
            this.setData({
                title: options.tip,
                toolNum: options.type - 1,
                timu: JSON.parse(options.timu),
                array: JSON.parse(options.array),
                arrayO: JSON.parse(options.arrayO),
                array1: JSON.parse(options.array1),
            });
            console.log('array1', this.data.array1);
        } else if (options.type == "6") {
            this.setData({
                title: options.tip,
                toolNum: options.type - 1,
                timu: JSON.parse(options.timu),
                array: JSON.parse(options.array),
            });
            console.log(this.data.timu);
        } else {
            this.setData({
                title: options.tip,
                toolNum: options.type - 1,
                timu: JSON.parse(options.timu),
                array: JSON.parse(options.array),
                arrayO: JSON.parse(options.arrayO),
            });
            console.log(this.data.array);
        }

    },
    bindPickerChange(e) { // 身高picker选择器height
        this.animate();
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            index: e.detail.value,
            height: this.data.array[e.detail.value],
        })
        console.log('身高', this.data.array[e.detail.value]);
        if (this.data.toolNum == '5') {
            this.setData({
                layerPopup: true
            });
            return
        }
        this.setData({
            id: null,
            progress: this.data.progress + 1,
        });
    },
    bindPickerChange1(e) { // 体重picker选择器weight
        this.animate();
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            indexO: e.detail.value,
            weight: this.data.arrayO[e.detail.value],
        })
        console.log('体重', this.data.arrayO[e.detail.value]);
        // setTimeout(() => {
        this.setData({
            id: null,
            progress: this.data.progress + 1,
        });
        // }, 1000)
        console.log(this.data.progress);
        if (this.data.progress == '3' && this.data.toolNum !== 3) {
            console.log('跳出弹窗观看视频进行跳转', '性别', this.data.sex, '身高', this.data.height, '体重', this.data.weight);
            this.setData({
                layerPopup: true
            })
        }
    },
    bindPickerChange2(e) { // 体重picker选择器weight1
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            index1: e.detail.value,
            weight1: this.data.array1[e.detail.value],
        })
        console.log('体重', this.data.array1[e.detail.value]);
        this.setData({
            id: null,
            progress: this.data.progress + 1,
        });
        console.log(this.data.progress, this.data.toolNum);
        if (this.data.toolNum == 3) {
            console.log('性别', this.data.sex, '年纪', this.data.height, '身高', this.data.weight, '体重', this.data.weight1);
            this.setData({
                layerPopup: true
            })
        }
    },
    animate() {
        const animation = tt.createAnimation({
            duration: 500,
        });
        this.animation = animation;
        // this.animation.opacity(0).step({
        //     duration: 500,
        // }).opacity(1).step({
        //     duration: 500,
        // });
        this.animation.translateX('400px').step({
            duration: 10,
        }).translateX('0px').step({
            duration: 1000,
        })
        this.setData({
            animationData: this.animation.export(),
        });
    },
    toResult() {
        if (this.data.toolNum == '0') {
            let bmi = this.data.weight / ((this.data.height / 100) * (this.data.height / 100))
            const BMI = (Math.round(bmi * 100) / 100).toFixed(1)
            console.log(BMI);
            this.setData({
                BMI
            });
            if (BMI > 18.511 && BMI < 23.911) {
                console.log('正常');
                this.setData({
                    value: '正常'
                })
            } else if (BMI > 24.011 && BMI < 27.911) {
                console.log('超重');
                this.setData({
                    value: '超重'
                })
            } else if (BMI > 28.011) {
                console.log('肥胖');
                this.setData({
                    value: '肥胖'
                })
            } else if (BMI < 18.511) {
                console.log('过瘦');
                this.setData({
                    value: '过瘦'
                })
            };
            tt.navigateTo({
                url: '/pages/result/result?tools=bmi&bmi=' + this.data.BMI +
                    '&value=' + this.data.value
            });
        } else if (this.data.toolNum == '1') {
            let cos = this.data.height / this.data.weight
            const COS = (Math.round(cos * 100) / 100).toFixed(1)
            console.log(COS, this.data.sex);
            if (this.data.sex == '男生') {
                if (COS > 1.00) {
                    this.setData({
                        cosValue: '中心性肥胖'
                    })
                } else {
                    this.setData({
                        cosValue: '非中心性肥胖'
                    })
                }
                console.log(this.data.cosValue);
                tt.navigateTo({
                    url: '/pages/result/result?tools=cos&value=' + this.data.cosValue
                        //  + '&waist=' + this.data.waist // 指定页面的url
                });
            } else {
                if (COS > 0.90) {
                    this.setData({
                        cosValue: '中心性肥胖'
                    })
                } else {
                    this.setData({
                        cosValue: '非中心性肥胖'
                    })
                }
                console.log(this.data.cosValue);
                tt.navigateTo({
                    url: '/pages/result/result?tools=cos&value=' + this.data.cosValue
                        //  + '&waist=' + this.data.waist // 指定页面的url
                });
            }
        } else if (this.data.toolNum == '2') {
            if (this.data.sex == '男生') {
                let a = this.data.height * 0.74
                let b = this.data.weight * 0.082 + 44.47
                let c = a - b
                let bfr = c / this.data.weight
                console.log(bfr);
                const BFR = (Math.round(bfr * 100) / 100).toFixed(1)
                console.log(BFR);
                if (BFR > 0.25) {
                    console.log('肥胖');
                    this.setData({
                        bfrValue: '肥胖'
                    })
                } else {
                    console.log('正常');
                    this.setData({
                        bfrValue: '正常'
                    })
                }
                this.setData({
                    BFR
                });
                tt.navigateTo({
                    url: '/pages/result/result?tools=bfr&value=' + this.data.bfrValue +
                        '&bfr=' + this.data.BFR // 指定页面的url
                });
            } else {
                let a = this.data.height * 0.74;
                let b = this.data.weight * 0.082 + 34.89;
                let c = a - b;
                console.log(a, b, c);
                let bfr = c / this.data.weight;
                console.log(bfr);
                const BFR = Math.round(bfr * 100) / 100;
                console.log(BFR);
                if (BFR > 0.30) {
                    console.log('肥胖');
                    this.setData({
                        bfrValue: '肥胖'
                    })
                } else {
                    console.log('正常');
                    this.setData({
                        bfrValue: '正常'
                    })
                }
                this.setData({
                    BFR
                })
                tt.navigateTo({
                    url: '/pages/result/result?tools=bfr&value=' + this.data.bfrValue +
                        '&bfr=' + this.data.BFR // 指定页面的url
                });
            }
        } else if (this.data.toolNum == '3') {
            if (this.data.sex == '男生') {
                let dcr = (66 + (13.7 * this.data.weight1) + (5 * this.data.weight) - (6.8 * this.data.height)).toFixed(1)
                console.log('每日所需kacl为', dcr);
                this.setData({
                    dcr
                })
                tt.navigateTo({
                    url: '/pages/result/result?tools=dcr&dcr=' + this.data.dcr
                });
            } else {
                let dcr = 655 + (9.6 * this.data.weight1) + (1.7 * this.data.weight) - (4.7 * this.data.height)
                console.log('每日所需kacl为', dcr);
                this.setData({
                    dcr
                })
                tt.navigateTo({
                    url: '/pages/result/result?tools=dcr&dcr=' + this.data.dcr
                });
            }
        } else if (this.data.toolNum == '4') {
            let weight = this.data.weight;
            if (this.data.sex == '男生') {
                let hwr = ((this.data.height - 80) * 0.7).toFixed(1);
                console.log('健康体重范围', hwr);
                if (weight > 0.9 * hwr && weight < 1.1 * hwr) {
                    console.log('正常');
                } else if (weight < 0.9 * hwr && weight > 0.8 * hwr) {
                    console.log('过轻');
                } else if (weight < 1.2 * hwr && weight > 1.1 * hwr) {
                    console.log('过重');
                } else if (weight < 0.8 * hwr) {
                    console.log('不足');
                } else if (weight > 1.2 * hwr) {
                    console.log('肥胖');
                }
                this.setData({
                    hwr
                });
                tt.navigateTo({
                    url: '/pages/result/result?tools=hwr&hwr=' + this.data.hwr // 指定页面的url
                });
            } else {
                let hwr = ((this.data.height - 70) * 0.6).toFixed(1);
                console.log('健康体重范围', hwr);
                if (weight > 0.9 * hwr && weight < 1.1 * hwr) {
                    console.log('正常');
                } else if (weight < 0.9 * hwr && weight > 0.8 * hwr) {
                    console.log('过轻');
                } else if (weight < 1.2 * hwr && weight > 1.1 * hwr) {
                    console.log('过重');
                } else if (weight < 0.8 * hwr) {
                    console.log('不足');
                } else if (weight > 1.2 * hwr) {
                    console.log('肥胖');
                }
                this.setData({
                    hwr
                });
                tt.navigateTo({
                    url: '/pages/result/result?tools=hwr&hwr=' + this.data.hwr // 指定页面的url
                });
            }
        } else if (this.data.toolNum == '5') {
            let height = this.data.height;
            let sfh = (height * 40).toFixed(1);
            console.log(sfh, 'ml水');
            this.setData({
                sfh
            });
            tt.navigateTo({
                url: '/pages/result/result?tools=sfh&sfh=' + this.data.sfh // 指定页面的url
            });
        } else if (this.data.toolNum == '6') {
            let height = this.data.height;
            let weight = this.data.weight;
            let rcb = (height * weight * 1.036).toFixed(1);
            console.log('消耗', rcb, 'k热量');
            this.setData({
                rcb
            });
            tt.navigateTo({
                url: '/pages/result/result?tools=rcb&rcb=' + this.data.rcb
            });
        }
    },
    itemClick(e) {
        // console.log(e.currentTarget.dataset);
        // var index1 = e.currentTarget.dataset.fs
        // var indexArr = this.data.choiceArray
        // indexArr.push(index1)
        // this.setData({
        //     id: index1,
        //     choiceArray: indexArr // choiceArray用来存放选择的选项
        // })
        // console.log(this.data.choiceArray);
        // if ((this.data.progress + 1) == this.data.timu.length) { // 答完题跳转
        //   let sum = 0;
        //   let arr = this.data.choiceArray
        //   arr.forEach(item => {
        //     sum = sum + item
        //   })
        //   console.log(sum, 'sum跳转');
        //   this.setData({
        //     lookResultLayer: true,
        //   })
        //   return
        // }
        // setTimeout(() => {
        // if (this.data.progress == '0') {
        //     this.setData({
        //         id: null,
        //         progress: this.data.progress + 1
        //     });
        // }
        // }, 1000)

        if (this.data.progress == '0') {
            this.setData({
                id: null,
                sex: e.currentTarget.dataset.value,
                progress: this.data.progress + 1
            });
            this.animate();
        }
        // console.log(this.data.sex);
    },
    closeClick() {
        setTimeout(() => {
            this.setData({
                layerPopup: false,
            });
            wx.navigateBack({
                delta: 1
            })
        }, 50);
    },
})